
#{extends 'main.html' /}
#{set title:'TopicPage' /}


<script type="text/javascript">


	$(function() {
		$('#renameTopics').hide();
		$('#otherTopics').hide();
		$('#topicslist').hide();
		$('#typemsg').hide();
		$('#bodymessage').hide();
		$('#uu').hide();
		$('#tt').hide();
		$('#create').hide();
		
		$('#TagBox').hide();
		$('#AddTag').hide();
		$('#Tag').hide();
		$('#TagOptions').hide();
		$('#EditBox').hide();
		$('#Cancel').hide();
		$('#hideTags').hide();
		$('#hideOptions').hide();
		$('#overlay').hide();
		if(${canLeadOrg} == 1){
			javascript:getOrganizers();
		} else {
			$('#restrictOrganizer').hide();
			$('#input').hide();
		}
			});
		function relate(){
		$('#r').fadeOut(1000);
		$('#typemsg').fadeIn(1000);
		$('#bodymessage').fadeIn(1000);
		$('#uu').fadeIn(1000);
		$('#tt').fadeIn(1000);
		$('#create').fadeIn(1000);
		$('#topicslist').fadeIn(1000);
		}
		function createRel(){
				$.getJSON('@{Application.addRelationtoTopic()}', {
					'firstId': '${topicId}' ,
					'secondName':$("select[id$='mydropdowntopics'] :selected").val(),
					'body':document.getElementById("bodymessage").value,
					'name':document.getElementById("typemsg").value
					},function(data){
						$('#one').jGrowl(data.res);
								})
			}

		function renameRelation(){
			$('#renameTopics').fadeIn(1000);
			$('#ren').fadeOut(1000);
		}
		function renameRel(){
			$.getJSON('@{TopicIdeaController.renameTopicRelation()}', {
				'topicIdOne': '${topicId}' ,
				'relationName':$("select[id$='rename'] :selected").val(),
				'newname':document.getElementById("newName").value
				},function(data){
					$('#one').jGrowl(data.box);
							});
		}

		function removeRel(){
		$('#rem').fadeOut(1000);
		$('#otherTopics').fadeIn(1000);
		}


		function DelRel(){
			
			$.getJSON('@{TopicIdeaController.removeTopicRelation()}', {
					'topicIdOne': '${topicId}' ,
					'relationName':$("select[id$='deletedRel'] :selected").val()
					},function(data){
						$('#one').jGrowl(data.box);
								});
								
		}


function Vote (ideaId){
    $("#votesNum"+ideaId).animate({fontSize:"3em"},"fast");

    document.getElementById("votesNum"+ideaId).innerHTML = parseInt(document.getElementById("votesNum"+ideaId).innerHTML) + 1;
    $("#votesNum"+ideaId).animate({fontSize:"1em"},"fast");
    $("#Vote"+ideaId).hide(1000);
    $("#unVote"+ideaId).show(1000);

    voteNw(ideaId);
};
function unVote(ideaId){
   $("#votesNum"+ideaId).animate({fontSize:"3em"},"fast");
    document.getElementById("votesNum"+ideaId).innerHTML = parseInt(document.getElementById("votesNum"+ideaId).innerHTML) - 1;
     $("#votesNum"+ideaId).animate({fontSize:"1em"},"fast");
    $("#unVote"+ideaId).hide(10);
    $("#Vote"+ideaId).show(1000);
    unvoteNw(ideaId);
  };


  function voteNw(ideaId){
      $.ajax({
	type: "POST",
	url: '@{TopicIdeaController.voteForIdea()}',
	data: {'ideaId':ideaId}
	});
         $('#one').jGrowl("ajax function ra7et succefully");

       
  }
  
function unvoteNw(ideaId){
      $.ajax({
	type: "POST",
	url: '@{TopicIdeaController.unvoteForIdea()}',
	data: {'ideaId':ideaId}
	})
	
	}


function hideThisTopic() {
        $('#hide').fadeOut(10);
        $('#unhide').fadeIn(10);
        $('#invite').fadeIn(10);
	$.ajax({
	type: "POST",
	url: '@{TopicIdeaController.hideTopic()}',
	data: {'topicId':'${topicId}'}
	})
	checkHidden();
	}

function unhideThisTopic() {
        $('#hide').show();
        $('#unhide').hide();
        $('#invite').hide();
	$.ajax({
	type: "POST",
	url: '@{TopicIdeaController.unhideTopic()}',
	data: {'topicId':'${topicId}'}
	})
	checkUnhidden();
	}
function checkHidden() {
	$.getJSON('@{TopicIdeaController.hideTopic(topicId)}', function(data) {
	$('#one').jGrowl(data.x);
	});
	}
function checkUnhidden() {
	$.getJSON('@{TopicIdeaController.unhideTopic(topicId)}', function(data) {
	$('#one').jGrowl(data.x);
	});
	}
function invite(){
    names="";
 //  $('#one').jGrowl("da5alna el javascript method invite");
   $.getJSON('@{TopicIdeaController.inviteToTopic(topicId)}', function(data) {
       $(".invitees").toggle();
            names = data.names.split("^");
            if(names == ""){
            	$(".invitees").hide();
            	$('#one').jGrowl("no idea developers to invite!")
            }
        else{  for (i =0; i< names.length; i++){
         newDiv = "<div id=\""+i+"\"><Button class=\""+i+"\"  onclick=\'javascript:doAnyth("+i+",\""+ names[i]+"\")\' > \""+names[i]+"\" </Button> </br> </div>"
           var temp = document.getElementById("invitees").innerHTML;
           document.getElementById("invitees").innerHTML = newDiv;
           document.getElementById("invitees").innerHTML += temp;
        }}
    });
	}
function doAnyth(id, name){
   // $('#one').jGrowl(id);
    $('#'+id).hide();
    $.ajax({
	type: "POST",
	url: '@{TopicIdeaController.inviteIdeaDev()}',
	data: {'topicId':'${topicId}', 'ideaDeveloperName':name}
	});
}
function hideDiv(){
     $(".invitees").hide();
}


    </script>


<script type="text/javascript">
     var type1="joinedIdeaDeveloper";
     var type2="NotjoinedIdeaDeveloper";
     var type3="OrgOrOrgLeadOpenTopic";
     var type4="OrgOrOrgLeadCloseTopic";
     var type5="OrgOrOrgLeadPromoteTopic";

$(document).ready(function display2() {

$.getJSON('@{TopicIdeaController.canFollowTopic()}', {'topicId': '${topicId}'}, function(data){


if(document.getElementById("type").value==type1){


if(data.followTopic == "you are already a follower"){
		$('#follow').hide();
		$('#unfollow').show();
	}
	else{
		$('#unfollow').hide();
	$('#follow').show();
	}
}
});
});

$(document).ready(display('${page}','${total}'));

function display(page,total) {
$.getJSON('@{TopicIdeaController.displayIdeasTopics()}',{'topicId':'${topicId}','ideaDeveloperId':'${ideaDeveloperId}',
'page':page,'total':total}, function(data) {

document.getElementById('page').value=data.page;
document.getElementById('total').value=data.total;
 $('#next').hide();
if(data!=null){

    if(data.count>0){
            $('#next').show();
    }
    var ideasDesrList={};
    var ideasIdList={};
    var ideaDeveloperNameList={};
    var ideaDeveloperIdList={};
    var listofIdeasVoted={};
    var ideasTitlelist={};
    var ideasPromoted={};
    var ideasReported={};
    var numberOfVotes={};
    var numberOfReported={};

            if(data.ideasTitle.length>0){
     ideasDesrList = data.ideasDescription.split("&&");
     ideasIdList  =data.ideasId.split("&&");
     ideaDeveloperNameList= data.ideaDeveloperName.split("&&");
     ideaDeveloperIdList= data.ideaDeveloperIds.split("&&");
     listofIdeasVoted=data.IdeasVotedId.split("&&");
    ideasTitlelist=data.ideasTitle.split("&&");
    ideasPromoted=data.promoted.split("&&");
    ideasReported=data.ideasReported.split("&&");
    numberOfVotes=data.numberOfVotes.split("&&");
    numberOfReported=data.numberOfReported.split("&&");
    actionPlans=data.actionPlans.split("&&");

    if(document.getElementById("type").value==type1||document.getElementById("type").value==type3){

     for(var i = 0 ; i < ideasDesrList.length ; i=i+1){

  lol(ideasIdList[i], ideaDeveloperIdList[i],ideaDeveloperNameList[i],
  ideasTitlelist[i],ideasDesrList[i],numberOfVotes[i],"prepend",actionPlans[i]);

// $('#one').jGrowl(ideasIdList[i]);


     if(ideasPromoted[i]>0){
document.getElementById("promoteStatus"+ideasIdList[i]).innerHTML="This idea Is promoted For Execution";

           if(actionPlans[i]==0){
            
           if(document.getElementById("type").value==type3){
        	   $('#StartActionPlan'+ideasIdList[i]).show();
          $('#Demote'+ideasIdList[i]).show();
          $('#Promote'+ideasIdList[i]).hide();
           }
       }else{
   $("<a id="+"ViewActionPlan"+ideasIdList[i]+"  href=@{ActionPlanController.ActionPlanOrganizer()}?actionPlanId="+actionPlans[i]+">ViewActionPlan</a>")
              .appendTo(document.getElementById("totalideadiv"+ideasIdList[i]));
       }
     } else{

         if(listofIdeasVoted[i]>0){
        $("#unVote"+ideasIdList[i]).show();
     }else{
       $("#Vote"+ideasIdList[i]).show();
     }
         if(document.getElementById("type").value==type3){
          $('#Promote'+ideasIdList[i]).show();
          $('#Demote'+ideasIdList[i]).hide();
         }

          if(ideaDeveloperIdList[i]=='${ideaDeveloperId}'&&document.getElementById("type").value==type1){
          $('#Delete'+ideasIdList[i]).show();
          $('#Tag'+ideasIdList[i]).show();
     }
       if(document.getElementById("type").value==type3){
          $('#Delete'+ideasIdList[i]).show();
           $('#Tag'+ideasIdList[i]).show();
     }



         if(document.getElementById("type").value==type1){
 if(ideasReported[i]==0&&ideaDeveloperIdList[i]!='${ideaDeveloperId}'){
        $("#Report"+ideasIdList[i]).show();
     }

     }
if(document.getElementById("type").value==type3){
    if(numberOfReported[i]!=0){


    document.getElementById("reported"+ ideasIdList[i]).innerHTML=numberOfReported[i]+"  persons reported this Idea as spam delete it if you want";
     }
     }



     }
     
      showIdeaTags(ideasIdList[i],"idea");
     }

  }   else{
               
     for(var i = 0 ; i < ideasDesrList.length ; i=i+1){
lol(ideasIdList[i], ideaDeveloperIdList[i],ideaDeveloperNameList[i],
  ideasTitlelist[i],ideasDesrList[i],numberOfVotes[i],"prepend",actionPlans[i]);
  showIdeaTags(ideasIdList[i],"idea");
  if(ideasPromoted[i]>0){
document.getElementById("promoteStatus"+ideasIdList[i]).innerHTML="This idea Is promoted For Execution";
if(actionPlans[i]!=0){
  $("<a id="+"ViewActionPlan"+ideasIdList[i]+"  href=@{ActionPlanController.ActionPlanOrganizer()}?actionPlanId="+actionPlans[i]+">ViewActionPlan</a>")
              .appendTo(document.getElementById("totalideadiv"+ideasIdList[i]));
}
  }

         }
                }
            }else{
               document.getElementById('noPosted').innerHTML="No posted Ideas";

                    }

if(document.getElementById("type").value==type1||document.getElementById("type").value==type3){
     if(data.ideasdrafted.length==0 ){
         document.getElementById('noDrafted').innerHTML="no drafted ideas";

     }else{
     
        var listDraftedideas={};
    var listDraftesideasId={};
    var listDraftesideasTitle={};
    listDraftedideas=data.ideasdrafted.split("&&");
     listDraftesideasId=data.ideasdraftedId.split("&&");
     listDraftesideasTitle=data.ideasdraftedTitle.split("&&");
     for(var i = 0 ; i < listDraftedideas.length ; i=i+1){

        lol2(listDraftesideasId[i],listDraftesideasTitle[i],listDraftedideas[i]);

     }
     }

}

if(document.getElementById("type").value==type3){
	$('#showDuplicatedButton').slideDown();
        $('#badawy').show();
        $('#inviteHere').show();
   $( document.getElementById("TagTopic")).show();
                if(data.topicPromoted>0){
                    $(document.getElementById("PromoteForExecution")).show();
                }else{
                    $(document.getElementById("CloseTopic")).show();
                }

                 if(data.topicHidden>0){
                    $(".unhide").show();
                    $(".invite").show();
                }else{
                    $(".hide").show();
                }

            }
            if(document.getElementById("type").value==type4){
            	$('#showDuplicatedButton').slideDown();
               $('#badawy').show();
               $('#inviteHere').show();
                $(document.getElementById("ReopenTopic")).show();
                document.getElementById("Status").innerHTML="This Topic is Closed"
            }
            if(document.getElementById("type").value==type5){
               $('#badawy').show();
               $('#inviteHere').show();
            	$('#showDuplicatedButton').slideDown();
            	document.getElementById("promote").innerHTML="This topic is promoted for execution";
            }
            if(document.getElementById("type").value!=type5&&document.getElementById("type").value!=type4
        &&document.getElementById("type").value!=type2){
                $(document.getElementById("createYourOwnIdea")).show();
            }


            if((document.getElementById("type").value==type3||
            document.getElementById("type").value==type4)&& data.ideasDescription==0 ) {

                     $(document.getElementById("Delete")).show();
                    }
        if(document.getElementById("type").value==type2){
            document.getElementById("Status").innerHTML="You are not joined to the organization please join";
        }
     
  if('${share}'==1){
      $('#showMembers').show();
  }

}
if('${topic.closed}'==true){
            document.write("amira")
            document.getElementById("Status").innerHTML="This Topic is Closed"
        }
        if('${topic.promotedForExecution}'==true){
            document.getElementById("Status").innerHTML="This Topic is Promoted for Execution"
        }

showIdeaTags('${topicId}',"topic");

}
);

}

 function editDraftIdea(ideaId,descr,title){
         document.getElementById('overlay').style.height = overlayer()[1]+'px';
	$(document.getElementById('overlay')).fadeIn(1000);
              $('#editDraft').fadeIn(1000);
              document.getElementById('ideaid').value=ideaId;
              document.getElementById('drafttitle').value=title;
              document.getElementById('draftdescr').value= descr;
               $(document.getElementById("draftideadiv"+ideaId)).remove();
          }
 function discard(div){
     if(div=='editDraft'){
     slideup('editDraft');
              document.getElementById('ideaid').value="";
              document.getElementById('drafttitle').value="";
              document.getElementById('draftdescr').value= "";
              document.getElementById('draftdescrexp').value= "";
              document.getElementById('drafttitleexp').value= "";
               $('#overlay').fadeOut(1000);
     }else{
       document.getElementById("createTitle").value=" ";
document.getElementById("createDescr").value=" ";
document.getElementById("ideatitleexp").innerHTML="Title Required";
document.getElementById("ideadescrexp").innerHTML="Description Required ";
slideup('newidea');
     }
 }

           function postDraftIdea(ideaId){
               if(checkValidationDraft()){
              var title=document.getElementById("drafttitle").value;
                  var descr=document.getElementById("draftdescr").value;

                 $.post("@{TopicIdeaController.postDraftIdea()}",
                 {'ideaId':ideaId,'description':descr,'title':title
                      },
  function(data){
        lol(data.ideaId,'${ideaDeveloperId}','${ideaDeveloperName}',data.ideaTitle,
        data.ideaDescription,"0","append")
        $("#Vote"+ideaId).show();
   $("#Delete"+ideaId).show();
   $('#Tag'+ideaId).show();
   $('Comment'+ideaId).show();
    if(document.getElementById("type").value==type3){
         $("#Promote"+ideaId).show();
         }

   $(document.getElementById('draftdescr')).value="";
   $(document.getElementById('drafttitle')).value="";
     document.getElementById('drafttitleexp').innerHTML="";
   document.getElementById('draftdescrexp').innerHTML="";
   slideup('editDraft');

  document.getElementById('total').value = parseInt(document.getElementById('total').value) + 1;
  document.getElementById('noPosted').innerHTML="";
  $('#overlay').fadeOut(1000);
  },"json")
            }
            }

           


 function draftDraftIdea(ideaId){
     if(checkValidationDraft()){
             var title=document.getElementById("drafttitle").value;
                  var descr=document.getElementById("draftdescr").value;

                 $.post("@{TopicIdeaController.draftDraftIdea()}",
                 {'ideaId':ideaId,'description':descr,'title':title
                      },
  function(data){
        lol2(data.ideaId,data.ideaTitle,data.ideaDescription)

    document.getElementById('draftdescr').value="";
   document.getElementById('drafttitle').value="";
   document.getElementById('drafttitleexp').innerHTML="";
   document.getElementById('draftdescrexp').innerHTML="";
  $('#editDraft').fadeOut(1000);
  },"json")
 }
 }
   function slidedown(object) {
       $('#'+document.getElementById(object).id).slideDown();

};



   function slideup(object) {
       $('#'+document.getElementById(object).id).slideUp();

};


   function createpostIdea() {
       if(checkValidationCreate()){
       var descr=document.getElementById("createDescr").value;
       var title=document.getElementById("createTitle").value;
      // document.write(descr);
      //public static void createpostIdea(long topicId, long ideaDeveloperId,
        //		String descr, String title)
       $.post("@{TopicIdeaController.createpostIdea()}", {'id':'${topicId}' ,"descr":descr,"title":title ,"whereIdeaExist":"topic"},
  function(data){
  lol(data.ideaId, '${ideaDeveloperId}','${ideaDeveloperName}',data.title,data.description,data.numberOfVotes,"append");

  $("#Vote"+data.ideaId).show();
   $("#Delete"+data.ideaId).show();
   $('#Tag'+data.ideaId).show();
   $('Comment'+data.ideaId).show();
    if(document.getElementById("type").value==type3){
         $("#Promote"+data.ideaId).show();
         }

  document.getElementById("createTitle").value="";
document.getElementById("createDescr").value="";
document.getElementById("ideatitleexp").innerHTML="Title Required";
document.getElementById("ideadescrexp").innerHTML="Description Required";
$('#newidea').fadeOut(1000);
 document.getElementById('total').value = parseInt(document.getElementById('total').value) + 1;
 document.getElementById('noPosted').innerHTML="";
}, "json");

}
   };


   function draftIdea() {
   if(checkValidationCreate()){
var descr=document.getElementById("createDescr").value;
var title=document.getElementById("createTitle").value;
       $.post("@{TopicIdeaController.draftIdea()}", {'id':'${topicId}' ,"descr":descr ,'title':title,'whereIdeaExist':"topic"},
  function(data){
       lol2(data.ideaId,data.title,data.description);
$(document.getElementById('create')).value=" ";
document.getElementById("createTitle").value=" ";
document.getElementById("createDescr").value=" ";
document.getElementById("ideatitleexp").innerHTML="Title Required ";
document.getElementById("ideadescrexp").innerHTML=" Description Required";
document.getElementById('noDrafted').innerHTML="";
$('#newidea').fadeOut(1000);
}, "json");

}
   };

function showTotalIdeaDiv(ideaId){
   
    $(".toggleable").hide(1000);
$("#totalideadiv"+ideaId).toggle(1000);

  
}

function showideabuttons(ideaId){
     $('#'+document.getElementById("ideabuttons"+ideaId).id).show();

}


function lol(ideaId,ideaDeveloperId,ideaDeveloperName,ideaTitle,ideaDescr,numberOfVotes,howToInsert){
        if(howToInsert=="append"){
    $("<div id="+"bigideadiv"+ideaId+"></div>").appendTo(document.getElementById("posted"));

        }else{
           $("<div id="+"bigideadiv"+ideaId+"></div>").prependTo(document.getElementById("posted"));
        }
  $("<div id="+"ideadiv"+ideaId+" class ="+"ideadiv"+"  onclick='javascript:showTotalIdeaDiv("+ideaId+")' >"
    +"<a href='/UserProfile/OtherUserProfile?id="
             +ideaDeveloperId+"'>Author : "+ideaDeveloperName +"</a>"+"</div>").
             appendTo(document.getElementById("bigideadiv"+ideaId))
    $("<br> <label> Title:" +ideaTitle+"</label>").appendTo(document.getElementById("ideadiv"+ideaId))
      $("<a href=@{TopicIdeaController.checkAuthorizationToViewIdea()}?ideaId="+ideaId+">GO To The Idea</a>").appendTo(document.getElementById("ideadiv"+ideaId))
$("<div id="+"totalideadiv"+ideaId+" class ="+"toggleable"+" style="+"display:none"+" >"+"<p> Description"+ideaDescr+"</p>"+"</div>").
    appendTo(document.getElementById("bigideadiv"+ideaId));
$("<aa >"+"NumberOf Votes : "+"</aa><br>").appendTo(document.getElementById("totalideadiv"+ideaId));
 $("<aa id="+"votesNum"+ideaId+">"+numberOfVotes+"</aa><br>").appendTo(document.getElementById("totalideadiv"+ideaId));
 $("<aa id="+"reported"+ideaId+"></aa><br>").appendTo(document.getElementById("totalideadiv"+ideaId));
 $("<aa id ="+"promoteStatus"+ideaId+"></aa><br>").appendTo(document.getElementById("totalideadiv"+ideaId));
 $("<aa >"+"Idea Tags : "+"</aa><br>").appendTo(document.getElementById("totalideadiv"+ideaId));
 $("<div id="+"ideaTags"+ideaId+"></div>").appendTo(document.getElementById("totalideadiv"+ideaId));
 $("<div id="+"ideabuttons"+ideaId+" ></div>").appendTo(document.getElementById("totalideadiv"+ideaId));
$("<a id="+"StartActionPlan"+ideaId+" style="+"display:none"+" href=@{ActionPlanController.StartActionPlan()}?ideaId="+ideaId+">StartActionPlan</a>")
           .appendTo(document.getElementById("totalideadiv"+ideaId));
    $("<input id="+"Tag"+ideaId
             +" type=submit style="+"display:none"+" value=\"Edit Tags\" onclick='javascript:showTagTag("+ideaId+",\"idea\")'/>").
             appendTo(document.getElementById("ideabuttons"+ideaId));
$("<input id="+"Report"+ideaId
             +" type=submit value=ReportAsSpam style="+"display:none"+" onclick='javascript:reportAsSpam("+ideaId+")'/>").
             appendTo(document.getElementById("ideabuttons"+ideaId));
   $("<input id="+"unVote"+ideaId +" type=submit style="+"display:none"+" onclick='javascript:unVote("+ideaId+")' name=hello value=unVote />")
         .appendTo(document.getElementById("ideabuttons"+ideaId));
   $("<input id="+"Vote"+ideaId +" type=submit style="+"display:none"+" onclick='javascript:Vote("+ideaId+")' name=hello value=Vote />")
        .appendTo(document.getElementById("ideabuttons"+ideaId));

   $("<input id="+"Comment"+ideaId
             +" type=submit value=\"Comments\"  onclick=\"location.href=\'@{TopicIdeaController.checkAuthorizationToViewIdea()}?ideaId=" + ideaId +"\'\"/>").

appendTo(document.getElementById("ideabuttons"+ideaId));

    $("<input id="+"Promote"+ideaId +" type=submit style="+"display:none"+" onclick='javascript:promoteIdea("+ideaId+")' name=hello value=Promote />")
        .appendTo(document.getElementById("ideabuttons"+ideaId));

    $("<input id="+"Demote"+ideaId +" type=submit style="+"display:none"+" onclick='javascript:demoteIdea("+ideaId+")' name=hello value=Demote />")
        .appendTo(document.getElementById("ideabuttons"+ideaId));
    
    $("<input id="+"MarkDuplicates"+ideaId
            +" type=submit value=\"Mark Duplicates\"  onclick=\"location.href='@{MarkAsDuplicatesController.markDuplicates()}?id="+ideaId+"'\"/>")
		.appendTo(document.getElementById("ideabuttons"+ideaId));

        $("<input id="+"Delete"+ideaId +" type=submit style="+"display:none"+" onclick='javascript:deleteIdea("+ideaId+")' name=hello value=Delete />")
        .appendTo(document.getElementById("ideabuttons"+ideaId));


}
function lol2(ideaId,ideaTitle,ideaDescr){
    $("<div id="+"draftideadiv"+ideaId+"><p> Title :"+ideaTitle+"</p><p> Descr :"+ideaDescr+"</p> \n\
<input type=submit value=PostDraftIdea onclick='javascript:editDraftIdea("+ideaId+",\""+ideaDescr+"\",\""+ideaTitle+"\")'/>"
 +"</div>").
             appendTo(document.getElementById("drafted"))


}
function reportAsSpam(ideaId){
      $.ajax({
	type: "POST",
	url: '@{TopicIdeaController.reportAsSpam()}',
	data: {'id':ideaId,'ideaDeveloperId':'${ideaDeveloperId}','type':"idea"}
	});
        $(document.getElementById("Report"+ideaId)).hide();
}


        function deleteIdea(ideaId){

      $.getJSON('@{TopicIdeaController.deleteIdea()}',{'ideaId':ideaId,'aloneOrNot':"notalone"},function(data){
          //$('#one').jGrowl(data.x);

          //if(document.getElementById("bigideadiv"+ideaId)!=null){
          document.getElementById("posted").innerHTML="";
         display(1,0);
          //}

          //if(document.getElementById("bigideadiv"+ideaId)!=null){
        

	});

        }

    function checkValidationCreate(){
     var title=document.getElementById("createTitle").value;
     var descr=document.getElementById("createDescr").value;
     	var isAlphaNeumeric =/^[0-9a-zA-Zs ]+$/;
                if(title==null||title==""){
                    document.getElementById("ideatitleexp").innerHTML="Title required"
                }else{
                    if(!(isAlphaNeumeric.test(title))){
                  //  if(title.indexOf("&")!=-1){
                         document.getElementById("ideatitleexp").innerHTML="Title can't contain Foreign Characters";
                    }else{
                        if(title.indexOf(" ")==0){
                           document.getElementById("ideatitleexp").innerHTML="Title can't start with spaces"; 
                        }else{
                        if(title.length>25){
                             document.getElementById("ideatitleexp").innerHTML="Title can't be more than 25 letters";
                        }else{
                     document.getElementById("ideatitleexp").innerHTML="" ;
                        }
                }
                }
                }
            
           
                if(descr==null||descr==""){
                    document.getElementById("ideadescrexp").innerHTML="Description required"

                }else{
                      if(!(isAlphaNeumeric.test(descr))){
                         document.getElementById("ideadescrexp").innerHTML="Title can't contain foreign keys";
                      }else{
                          if(descr.indexOf(" ")==0){
                               document.getElementById("ideadescrexp").innerHTML="descr can't start with space" ;
                          }
                    else{
                     document.getElementById("ideadescrexp").innerHTML="" ;
                }
                }
                }

if(document.getElementById("ideadescrexp").innerHTML=="" && document.getElementById("ideatitleexp").innerHTML==""){
    return true
}
else{
    return false;
}

         }


function checkValidationDraft(){
      var title=document.getElementById("drafttitle").value;
     var descr=document.getElementById("draftdescr").value;
     var isAlphaNeumeric =/^[0-9a-zA-Zs ]+$/;
                if(title==null||title==""){
                    document.getElementById("drafttitleexp").innerHTML="Title required"
                }else{
                    if(!(isAlphaNeumeric.test(title))){
                         document.getElementById("drafttitleexp").innerHTML="Title can't contain foreign keys";
                    }else{
                        if(title.indexOf(" ")==0){
                             document.getElementById("drafttitleexp").innerHTML="Title can't start with space";
                        }else{
                        if(title.length>25){
                             document.getElementById("drafttitleexp").innerHTML="Title can't be more than 25 letters";
                        }else{
                     document.getElementById("drafttitleexp").innerHTML="" ;
                        }
                }
                }
                }
                if(descr==null||descr==""){
                    document.getElementById("draftdescrexp").innerHTML="Description required"

                }else{
                     if(!(isAlphaNeumeric.test(descr))){
                         document.getElementById("draftdescrexp").innerHTML="Description can't contain Foreign characters";
                    }else{
                        if(descr.indexOf(" ")==0){
                            document.getElementById("draftdescrexp").innerHTML="Description can't start with space" ;
                        }else{
                     document.getElementById("draftdescrexp").innerHTML="" ;
                }
                }
                }

if(document.getElementById("draftdescrexp").innerHTML=="" && document.getElementById("drafttitleexp").innerHTML==""){
    return true
}
else{
    return false;
}

         }


 </script>


<script type="text/javascript">
var freeze = 0;
var follow = 0;
// var a = [document.getElementById("star1"), document.getElementById("star2"), document.getElementById("star3"), document.getElementById("star4"), document.getElementById("star5")]

function mouseonimage(id) {

	for(var i = 0; i < 5; i++) {
		a[i].src = "..\\..\\..\\public\\images\\disabledstar.png";
	}

	for(var i = 0; i < id; i++) {

		a[i].src = "..\\..\\..\\public\\images\\redstar.png";
	}

}

function mouseoutimage() {

	for(var i = 0; i < 5; i++) {
		a[i].src = "..\\..\\..\\public\\images\\star.png";
	}

	for(var i = freeze; i < 5; i++) {

		a[i].src = "..\\..\\..\\public\\images\\disabledstar.png";
	}

}

/* function resetstars(){

	for(var i = 0; i < 5; i++) {
		a[i].src = "..\\..\\..\\public\\images\\disabledstar.png";
	}

	freeze = 0;
} */

function loadRate() {
	
	$.getJSON('@{TopicIdeaController.getTopicRating()}', {'topicId':'${topicId}'},function(data){
		document.getElementById("currentRating").innerHTML=data.result;

	});
	
	$.getJSON('@{TopicIdeaController.alreadyRatedTopic()}', {'topicId':'${topicId}'},function(data){
		freeze = data.result;
		mouseoutimage();

	});

}

function rateTopic(rating) {

	$.getJSON('@{TopicIdeaController.rateTopic()}', {'rate':rating , 'topicId':'${topicId}'}, function(data) {

		freeze = data.result;
		mouseoutimage();
	});
	
	loadRate();

}



</script>

<
<script type="text/javascript">
function deleterelation(relationId){
	var answer = confirm("Are you sure you want to delete the topic relation?");
	var topicid=relationId;
	if (answer){

		$.getJSON(
		'@{TopicIdeaController.deleteTopicRelation()}',
		{
			'relationId' :relationId
		},
		function(data) {

			location.reload(true)
}, 'json')
	}
}


function LockTopic(type){
	
	$.getJSON(
			'@{TopicIdeaController.lockOrUnlockTopic()}',
{			'topicId' :'${topicId}',
		    'type' : type
		},
		function(data) {
				document.getElementById('result_lock').innerHTML = data.res;
			}, 'json')
		$('#lock_topic').toggle();
		$('#unlock_topic').toggle();
		
	}

/*$(document).ready(function() {
	 $.getJSON(
				'@{Application.incrementViews()}',
				{
					'id' : '${topicId}',
					'type':'topic'
				},

				function(data) {
				//	document.getElementById('numberofViews').innerHTML = data.res;
				}, 'json') 

});

*/


</script>

<script type="text/javascript">
function followTopic() {

 	$.getJSON('@{TopicIdeaController.followTopic()}',{'topicId': '${topicId}'},function(data){
 		$('#follow').hide();
 		$('#unfollow').show();
	});
}
</script>

<script type="text/javascript">
function unfollowTopic() {

	$.getJSON('@{TopicIdeaController.unfollowTopic()}',{'topicId': '${topicId}'},function(data){
		$('#follow').show();
		$('#unfollow').hide();
	});
}

function showBox() {
	$('#showBox').hide();
	$('#AddTag').show();
	$('#TagBox').show();
	$('#Cancel').show();
}

function hideBox() {
	$('#showBox').show();
	$('#AddTag').hide();
	$('#TagBox').hide();
	$('#Cancel').hide();
}

function showTags() {
	$('#Tag').slideDown();
	$('#hideTags').show();
	$('#showTags').hide();

}

function hideTags() {
	$('#Tag').slideUp();
	$('#showTags').show();
	$('#hideTags').hide();
}

function hideOptions() {
	$('#TagOptions').slideUp();
	$('#EditBox').slideUp();
	$('#hideOptions').hide();
}


function addEditedTag(deleted) {
	var isAlphaNeumeric =/^[0-9a-zA-Zs ]+$/;
	var type = document.getElementById("TagType").value;
	id = document.getElementById('TagTypeId').value;
	name = document.getElementById("EditBox").value;
	NoSpace = 1;
	for(i = 0; i < name.length; i++){
		if(name[i] == " "){
			NoSpace = 0;
		}
	}
	if(isAlphaNeumeric.test(name)){
	if(NoSpace){
	if(name.length > 25){
		$('#one').jGrowl("Tags should not exceed 25 characters !")
	} else if(name.length == ""){
		$('#one').jGrowl("Tag is empty !");
	}
	else{
	$.getJSON('@{TopicIdeaController.addTag()}',{'name' : name,'ID':id, 'type':type},function(data){
 	$('#one').jGrowl(data.box);
 	if ((data.box != "Already Exists") && (data.box != "Tags should not exceed 25 characters !") && (data.box != "Tag is empty !")) {
 	document.getElementById("Tag").innerHTML += "<input type=\"button\" value=\""+name+"\" id=\""+"Tag"+type+""+name+"\" onclick=\"showOptions('"+name+"')\" />";
 	removeTag(deleted);
 	document.getElementById("EditBox").value = "";
 	}
	});}} else {
		$('#one').jGrowl("Tags should not contain any spaces !");
	}} else {
		alert("Tags should be of alpha numeric form !");
	}
}

function showOptions(tagname){
	document.getElementById("TagOptions").innerHTML = "";
	document.getElementById("TagOptions").innerHTML += "<input type=\"button\" value=\"Edit "+tagname+"\" id=\""+"Edit "+tagname+"\" onclick=\"addEditedTag('"+tagname+"')\" />";
	document.getElementById("TagOptions").innerHTML += "<input type=\"button\" value=\"Remove "+tagname+"\" id=\""+"Remove "+tagname+"\" onclick=\"removeTag('"+tagname+"')\" />";
	//document.getElementById("TagOptions").innerHTML += "<input type=\"button\" value=\"Follow "+tagname+"\" id=\""+"Follow "+tagname+"\" onclick=\"followTag('"+tagname+"')\" />";
	$('#EditBox').slideDown();
	$('#TagOptions').slideDown();
	$('#hideOptions').show();
}

function addTag(id) {
	var isAlphaNeumeric =/^[0-9a-zA-Zs ]+$/;
	var type = document.getElementById("TagType").value;
	name = document.getElementById("TagBox").value;
	NoSpace = 1;
	for(i = 0; i < name.length; i++){
		if(name[i] == " "){
			NoSpace = 0;
		}
	}
	if(isAlphaNeumeric.test(name)){
	if(NoSpace){
	if(name.length > 25){
		$('#one').jGrowl("Tags should not exceed 25 characters !");
	} else if(name.length == ""){
		$('#one').jGrowl("Tag is empty !");
	}
	else{
	$.getJSON('@{TopicIdeaController.addTag()}',{'name' : name,'ID':id, 'type':type},function(data){
 	$('#one').jGrowl(data.box);
 	if ((data.box != "Already Exists") && (data.box != "Tags should not exceed 25 characters !") && (data.box != "Tag is empty !")) {
 	document.getElementById("Tag").innerHTML += "<input type=\"button\" value=\""+name+"\" id=\""+"Tag"+type+""+name+"\" onclick=\"showOptions('"+name+"')\" />";
 	document.getElementById("TagBox").value = "";
 	}
	});}} else {
		$('#one').jGrowl("Tags should not contain any spaces !");	
	}} else {
		$('#one').jGrowl("Tags should be of alpha numeric form !");
	}
}

function removeTag(name) {
	type = document.getElementById("TagType").value;
	id = document.getElementById('TagTypeId').value;
	document.getElementById("TagOptions").innerHTML = "";
	$.getJSON('@{TopicIdeaController.removeTag()}',{'name' : name,'ID': id, 'type':type},function(data) {
	$('#one').jGrowl(data.box);
	showTagTag(document.getElementById("TagTypeId").value,document.getElementById("TagType").value);
	$('#EditBox').hide();
});
}

function showTagTag(id, type){
	var tags={};
	document.getElementById("Tag").innerHTML ="";
	document.getElementById("TagTypeId").value = id;
	document.getElementById("TagType").value = type;
	document.getElementById('overlay').style.height = overlayer()[1]+'px';
	$(document.getElementById('overlay')).fadeIn(1000);
	$(document.getElementById("zeinTag")).fadeIn(1000);
	document.getElementById('zeinTag').focus();
	$.getJSON('@{TopicIdeaController.showTags()}',{'ID':id, 'type':type},function(data) {	
	if(data.box.length>0){
	tags = data.box.split("$$");
	for(var i = 0 ; i < tags.length ; i=i+1){
 	document.getElementById("Tag").innerHTML += "<input type=\"button\" value=\""+tags[i]+"\" id=\""+"Tag"+type+""+tags[i]+"\" onclick=\"showOptions('"+tags[i]+"')\" />";
 	 }
	}
});
}

function showIdeaTags(id, type){
	var tags={};
	$.getJSON('@{TopicIdeaController.showTags()}',{'ID':id, 'type':type},function(data) {
	tags = data.box.split("$$");
	if(type == "topic"){
	document.getElementById("TopicTags").innerHTML = "";
	for(var i = 0 ; i < tags.length ; i=i+1){
		document.getElementById("TopicTags").innerHTML+= "<a href=\"@{TagPage.TagView()}?name="+tags[i]+"\">" + ""+tags[i]+"" + "</a>  ";
 	 }
	} else {
	document.getElementById("ideaTags"+id).innerHTML = "";
	for(var i = 0 ; i < tags.length ; i=i+1){
		document.getElementById("ideaTags"+id).innerHTML+= "<a href=\"@{TagPage.TagView()}?name="+tags[i]+"\">" + ""+tags[i]+"" + "</a>  ";
 	 }}
});
}

function hideTagTag(){
	document.getElementById("TagBox").value = "";
	document.getElementById("EditBox").value = "";
	showIdeaTags(document.getElementById("TagTypeId").value, document.getElementById("TagType").value);
	hideTags();
	hideOptions();
	hideBox(); 
	$(document.getElementById("overlay")).fadeOut(1000);
	$(document.getElementById("zeinTag")).fadeOut(1000);
}

function overlayer(){
	 if (document.body.scrollHeight>document.body.offsetHeight){
		 return [document.body.scrollWidth,document.body.scrollHeight];
	 } else {
	 return [document.body.offsetWidth,document.body.offsetHeight];
	}
}


function showDuplicated(){
	if(document.getElementById("duplicatesShown?").value != "duplicatesShown"){
		showDuplicatedIdeas();
		document.getElementById("duplicatesShown?").value = "duplicatesShown";
		$(("#duplicateIdeas")).hide();
		$(("#duplicateIdeas")).slideDown(1000);
	} else {
		$(("#duplicateIdeas")).toggle(1000);
	}
}

function showDuplicatedIdeas(){
	var duplications = [];
	var singleDuplicate = [];
	var duplicateIdeasTitles = [];
	var infoOfIdea = [];
	$.getJSON('@{TopicIdeaController.showDuplicateIdeas()}',{'ID':${topicId},'type':'topic'},function(data){
	if(data.box.length != 0){
		duplications = data.box.split("$$");
		for(i = 0; i < duplications.length ; i++){
			singleDuplication = duplications[i].split("*$");
			sourceIdea = singleDuplication[0].split("!id#");
			document.getElementById("duplicateIdeas").innerHTML += "<div  id=\"Duplication"+sourceIdea[1]+"\" > </div><br>";
			document.getElementById("Duplication"+sourceIdea[1]+"").innerHTML += "<a onclick=\"showDuplicates('"+sourceIdea[1]+"')\">" + "Title: "+sourceIdea[0]+"" + "</a><br>";
			document.getElementById("Duplication"+sourceIdea[1]+"").innerHTML += "<a>" + "Description: "+sourceIdea[2]+"" + "</a><br>";
			document.getElementById("Duplication"+sourceIdea[1]+"").innerHTML += "<form id=\"Duplicates"+sourceIdea[1]+"\" style=\"border: 2px solid gray;\"> </form>";
			duplicateIdeasTitles = singleDuplication[1].split("$*");
			var k = 0;
			var duplicateIdeasIDS = [];
			while(k < duplicateIdeasTitles.length){
				infoOfIdea = duplicateIdeasTitles[k].split("!id#");
				//$('#one').jGrowl("<input type=\"checkbox\" id=\"DuplicateIdea"+(j+1)+"\" value=\""+infoOfIdea[1]+"\" />" + ""+infoOfIdea[0]+"");
				document.getElementById("Duplicates"+sourceIdea[1]+"").innerHTML += "<input type=\"checkbox\" name=\"duplicate\" value=\""+infoOfIdea[1]+"\" />";
				document.getElementById("Duplicates"+sourceIdea[1]+"").innerHTML += "<a  id=\"DuplicateIdea"+infoOfIdea[1]+"\" onclick=\"javascript:toggleDescription('"+infoOfIdea[1]+"')\">" + ""+infoOfIdea[0]+"" + "</a><br>";
				document.getElementById("Duplicates"+sourceIdea[1]+"").innerHTML += "<a  id=\"DuplicateIdeaDescription"+infoOfIdea[1]+"\">" + "Description: "+infoOfIdea[2]+"" + "</a> <br><br>";
				$(("#DuplicateIdeaDescription"+infoOfIdea[1]+"")).hide();
				k ++;
			}
			document.getElementById("Duplicates"+sourceIdea[1]+"").innerHTML += "<input type=\"button\" value=\"Merge with "+sourceIdea[0]+"\" id=\""+"Merge"+sourceIdea[1]+"\" onclick=\"javascript:mergeIdea('"+sourceIdea[1]+"')\" />";
			$(("#Duplicates"+sourceIdea[1]+"")).hide();
		} 
	} else {
		document.getElementById("duplicateIdeas").innerHTML += "<a>  No Duplicate Ideas  </a><br>";
	}
	});
}

function toggleDescription(ID){
	$(("#DuplicateIdeaDescription"+ID+"")).toggle(1000);	
}

function mergeIdea(ID){
	if(document.getElementById("Duplicates"+ID+"").duplicate.length != null){
	for (var i=0; i < document.getElementById("Duplicates"+ID+"").duplicate.length; i++){
	   if (document.getElementById("Duplicates"+ID+"").duplicate[i].checked){
	      notifyDuplicateOwner(ID, document.getElementById("Duplicates"+ID+"").duplicate[i].value);
		   deleteIdea(document.getElementById("Duplicates"+ID+"").duplicate[i].value);
		   $.getJSON('@{TopicIdeaController.removeDuplicatesRelation()}',{'ID':ID},function(data){}); 
	   }
   	}
	} else {
		if(document.getElementById("Duplicates"+ID+"").duplicate.checked){
			//$('#one').jGrowl(document.getElementById("Duplicates"+ID+"").duplicate.value);
			notifyDuplicateOwner(ID, document.getElementById("Duplicates"+ID+"").duplicate.value);
			deleteIdea(document.getElementById("Duplicates"+ID+"").duplicate.value);
			$.getJSON('@{TopicIdeaController.removeDuplicatesRelation()}',{'ID':ID},function(data){});
		}
	}
	document.getElementById("duplicateIdeas").innerHTML = "";
	window.setTimeout("showDuplicatedIdeas()",100);
}

function notifyDuplicateOwner(source, duplicate){
	$.ajax({
		type: "POST",
		url: '@{TopicIdeaController.notifyDuplicateOwner}',
		data: {'id':source, 'id2':duplicate}
		});
}

function showDuplicates(id){
	$(("#Duplicates"+id+"")).toggle(1000);
}
</script>


<script type="text/javascript">
function promoteIdea(ideaId){
	$.getJSON('@{TopicIdeaController.promoteIdea()}',{'ideaId':ideaId,'ideaDeveloperId':'${ideaDeveloperId}'},function(data){
 		$('#one').jGrowl(data.x);
 		$(document.getElementById("Promote"+ideaId)).hide();
 		$(document.getElementById("Demote"+ideaId)).show();
                $(document.getElementById("Delete"+ideaId)).hide();
                 $(document.getElementById("Tag"+ideaId)).hide();
                 $(document.getElementById("Vote"+ideaId)).hide();
                 $(document.getElementById("unVote"+ideaId)).hide();
                  document.getElementById("promoteStatus"+ideaId).innerHTML="This Idea is promoted for Execution";
                 $('#CloseTopic').hide();
                 $('#PromoteForExecution').show();
   $('#StartActionPlan'+ideaId).show();

	});
}
</script>
<script type="text/javascript">
function demoteIdea(ideaId){
	$.getJSON('@{TopicIdeaController.demoteIdea()}',{'ideaId':ideaId,'ideaDeveloperId':'${ideaDeveloperId}'},function(data){
 		$('#one').jGrowl(data.x);
 		$(document.getElementById("Promote"+ideaId)).show();
 		$(document.getElementById("Demote"+ideaId)).hide();
                $(document.getElementById("Vote"+ideaId)).show();
                 $(document.getElementById("Delete"+ideaId)).show();
                  $(document.getElementById("Tag"+ideaId)).show();
                  document.getElementById("promoteStatus"+ideaId).innerHTML="";
                  if(data.numberOfPromotedIdeas==0){
                       $('#CloseTopic').show();
                 $('#PromoteForExecution').hide();
                 $('#StartActionPlan'+ideaId).remove();
                  }
	});
}
</script>
<style>
.ideadiv {
	padding: 5px 10px;
	cursor: pointer;
	position: relative;
	background-color: #FFCCCC;
	margin: 1px;
}

.toggleable {
	padding: 5px 10px 15px;
	background-color: #F4F4F8;
}
</style>
<script type="text/javascript">
function showMembers(){
	if(document.getElementById("members").innerHTML==""){
		id = ${topicId};
		$.getJSON('@{BrowseController.browseMembersInTopicOrganization()}', {'topicId':id}, function(data) {
			var members = "";
			if(data.members != null){
				if(data.members != "-1"){
					var userNames = data.members.split('&&');
					for(var i = 0; i < userNames.length - 1; i = i+1){
						var user = userNames[i]
						members += "<a href='#' onclick=\"shareWith('" + user + "')\">" + user + "</a></br>";
					}
				} else {
					members += "No members to show";
				}
			}
			members += "<input type=\"button\" id=\"hideMembers\" value=\"Done!\" onclick=\"$('#members').fadeOut(1000)\"/>"
			document.getElementById("members").innerHTML = members;
			$('#members').hide();
			$('#members').toggle(1000);
		});
	} else {
		$('#members').toggle(1000);
	}
}
</script>
 
<script type="text/javascript">
function shareWith(user){
	$.getJSON('@{TopicIdeaController.shareTopic()}', {'recieverUserName':user, 'topicId':'${topicId}'}, function(data){
		$('#one').jGrowl(data.response);
	});
	//$('#members').hide(1000);

}
</script>
<script type="text/javascript">

function inviteAny() {
	//requestIdeaDeveloperToTopic(long topicId,String devName)
	$
	.getJSON(
			'@{Application.requestIdeaDeveloperToTopic()}',
			{
				'topicId' : document.getElementById("topicID").value,
				'devName' : document.getElementById("toBeInvited").value
			},
			function(data) {
				$('#one').jGrowl(data.res);
			});
}
function getTagsghUserNM(search) {

	if (search != "") {
		$(function() {
			$.getJSON('@{QuickSearchRendering.autoComplete1()}', {
				'search' : search
			}, function(data) {
				$("#toBeInvited").autocomplete({
					source : data.tags.split("&")
				});
			});

		});
	}
}

</script>
<script type="text/javascript">
	function getOrganizers(topicID) {

		document.getElementById("organizers").innerHTML = "";

		$
				.getJSON(
						'@{Application.getOrganizersTopic()}',
						{
							'topicID' : document.getElementById("topicID").value
						},
						function(data) {
							s = data.res.split("*");
							$('#one').jGrowl(s);
							var total = "<p><label>choose organizer to restrict</label><select id=\"org\">"
							for ( var i = 1; i < s.length; i = i + 1) {
								if (s[i] != "") {
									total += "<option selected value="+i+">"
											+ s[i] + "</option>";
								}
							}
							total += "</select></p>";
							document.getElementById("organizers").innerHTML = total;
						});

	}
	function resOrganizers() {

		var index = document.getElementById("org").selectedIndex
		var organizerName = document.getElementById("org").options[index].text
		var label="";
		var string ="";
		var t="";
		$.getJSON('@{Application.resOrganizersTopic()}', {
			'topicID' : document.getElementById("topicID").value,
			'organizerName' : organizerName
		}, function(data) {
        s=data.res.split("%^%");
		sfirst=s[0];
		spit=sfirst.split("&");
		
		if(spit[0].length>11)
	    {
		  string=spit[0]+"<BR/>";
		}
		if(spit[1].length>11)
		{
			string+="  "+spit[1];
		}
		spitt=s[1].split("&");
		if(spitt[0].length>11)
	    {
		  t=spitt[0]+"<BR/>";
		}
		if(spitt[1].length>11)
		{
			t+="  "+spitt[1];
		}
		if(string.length>0)
		{
			 label+="<label>"+organizerName+" is now restricted to this topic by removing him from organizing the following :<BR/>"+string+"</label><BR/>";
		}
        
        if(t.length>0)
        {
               label+="<BR/><label>"+organizerName+" can not be removed from organizing the following because last organizer on Topic or Entity :<BR/>"+t+"</label>";
       	}
        document.getElementById("label").innerHTML=	label;
		});

	}

</script>


</head>

<body>
    #{if topic.topicOrg}
		Organization:<a href="@{Application.OrganizationView(topic.topicOrg.name)}">${topic.topicOrg.name}</a>

		#{/if}

			#{if topic.topicEnt}
			 Organization:<a href="@{Application.OrganizationView(topic.topicEnt.liesIn.name)}">${topic.topicEnt.liesIn.name}</a> >
			 Entity:<a href="@{Application.EntityView(topic.topicEnt.id)}">${topic.topicEnt.name}</a>

			#{/if}
	<div id="content">
		<div class="Topic"
			style="width: 400px; padding: 20px; border: 9px solid gray; margin-left: 50px;">
			
		
                        <h2>Author: ${Author}</h2>
			<h2>Title: ${topicTitle}</h2>
			<h2>Description :${topicDescription}</h2>
			<h2>#Views: ${numberOfViews}</h2>


			 ${isOrganizerORIsCreator}
			#{if topicRelations} #{if isOrganizerORIsCreator} 
			#{list items:topicRelations, as: 'topicRelation' }

			<h3 id="${topicRelation.id}">
    		<a href="@{TopicIdeaController.checkAuthorizationToViewTopic(topicRelation.firstTopic)}">${topicRelation.topicById(topicRelation.firstTopic)}</a> 
    		${topicRelation.relationName}
      	 	<a href="@{TopicIdeaController.checkAuthorizationToViewTopic(topicRelation.secondTopic)}">${topicRelation.topicById(topicRelation.secondTopic)}</a> 
   
     		<a href="#"
     		onClick="javascript:deleterelation(${topicRelation.id})"
     		id="deleteRelation">Delete</a>
   			</h3>

			#{/list}
			 #{/if}
			  #{ifnot isOrganizerORIsCreator} 
			  #{list items:topicRelations, as: 'topicRelation' }


			<h3 id="${topicRelation.id}">
    		<a href="@{TopicIdeaController.checkAuthorizationToViewTopic(topicRelation.firstTopic)}">${topicRelation.topicById(topicRelation.firstTopic)}</a> 
    		${topicRelation.relationName}
       		<a href="@{TopicIdeaController.checkAuthorizationToViewTopic(topicRelation.secondTopic)}">${topicRelation.topicById(topicRelation.secondTopic)}</a> 
       		</h3>

			#{/list} 
			#{/ifnot} 
			#{/if}

			<p></p>

			<h5><span>Average Rate: </span><span id="currentRating"></span></h5>
			
			<div id="rate">

				<a href="javascript:void(0)"> <img id="reset" height="17"
					src="../../../public/images/reset.png" onclick="rateTopic(0)" 
				/></a>  <a href="javascript:void(0)"><img id="star1" height="20" 
					src="../../../public/images/disabledstar.png"
					onmouseover="mouseonimage(1)" onmouseout="mouseoutimage()"
					onclick="rateTopic(1)" 
				/></a><a href="javascript:void(0)"><img id="star2" height="20"
					src="../../../public/images/disabledstar.png"
					onmouseover="mouseonimage(2)" onmouseout="mouseoutimage()"
					onclick="rateTopic(2)" 
				/></a><a href="javascript:void(0)"><img id="star3" height="20"
					src="../../../public/images/disabledstar.png"
					onmouseover="mouseonimage(3)" onmouseout="mouseoutimage()"
					onclick="rateTopic(3)" 
				/></a><a href="javascript:void(0)"><img id="star4" height="20"
					src="../../../public/images/disabledstar.png"
					onmouseover="mouseonimage(4)" onmouseout="mouseoutimage()"
					onclick="rateTopic(4)" 
				/></a><a href="javascript:void(0)"><img id="star5" height="20"
					src="../../../public/images/disabledstar.png"
					onmouseover="mouseonimage(5)" onmouseout="mouseoutimage()"
					onclick="rateTopic(5)" 
				/></a>

				<script>

					var a = [document.getElementById("star1"), document.getElementById("star2"), document.getElementById("star3"), document.getElementById("star4"), document.getElementById("star5")];

					loadRate();

				</script>


			</div>

		</div>
              Topic tags:
		<div id="TopicTags" style="margin-top: 20px">
                  
                    <br>
                </div>
		<div id="TopicButtons" style="margin-top: 20px">

			<input type="submit" id="PromoteForExecution" style="display: none"
				value="Promote For execution" onclick="location.href= '@{TopicIdeaController.promoteTopic(topicId)}'" />
			<input type="submit" id="CloseTopic" style="display: none"
				value="Close" onclick=location.href='@{TopicIdeaController.closeTopic(topicId)}'>

			<!--
                      <a href='/TopicIdeaController/closeTopic?topicId=${topicId}'>Close</a>
                      -->
			<input type="submit" id="ReopenTopic" style="display: none"
				value="Reopen" onclick=location.href='@{TopicIdeaController.reOpenTopic(topicId)}' />
			<input type="submit" id="Delete" style="display: none" value="Delete"
				onclick=location.href='@{TopicIdeaController.deleteTopic(topicId)}' />
                                <input type="submit"
				id="TagTopic" style="display: none" value="Edit Tags"
				onclick="javascript:showTagTag(${topicId},'topic')" />

			<button id="hide" class="hide" style="display: none"
				onclick="javascript:hideThisTopic()">Hide</button>
			<button id="unhide" class="unhide" style="display: none"
				onclick="javascript:unhideThisTopic()">Unhide</button>
			<button id="invite" class="invite" style="display: none"
				onclick="javascript:invite()">Invite</button>
			<input type="button" style="display:none" id="showMembers" value="ShareTopic with members"
				onclick="showMembers()" />
                        <label id="promote"> </label>
                        <label id="Status"></label>

		</div>
              <div id="badawy" style="display:none">
		<input type="submit" id="r"  value="Relate Topic" onclick="relate()" />
		
		<div id="topicslist">
			#{ifnot topicsNames}


			<p>No Topics in the organization to relate with</p>

			#{/ifnot} #{if topicsNames} <br></br><select name="mydropdown"
				id="mydropdowntopics"> #{list items:topicsNames, as: 'task'
				}
				<option id="" value="${task}">${task}</option> #{/list}
			</select> #{/if}
<br></br>
		</div>
		<label for="typemsg" id="tt">Relation Name</label>
		 <input name="typemsg"
			id="typemsg" value="" type="text" /> 
			<br></br>
			<label for="bodymessage"
			id="uu">Description:</label><br></br>
		<textarea cols="60" rows="7" name="bodymessage" id="bodymessage"></textarea>
<br></br>
		<input type="submit" id="create" value="Add Relation"
			onclick="createRel()" />
		<br></br>
		<input type="submit" id="rem"
			value="Remove Relation with another Topic" onclick="removeRel()" />

		<div id="otherTopics">
			#{ifnot toBeDeleted}

			<p>No Relations to delete !!</p>

			#{/ifnot} #{if toBeDeleted} <select name="mydropdown" id="deletedRel">
				#{list items:toBeDeleted, as: 'task' }
				<option id="" value="${task}">${task}</option> #{/list}
			</select> #{/if} 
			<br></br>
			<input type="submit" id="delrel"
				value="Remove Selected Relation" onclick="DelRel()" />

		</div>

		<br></br>

                <input type="submit" id="ren" 
					value="Rename Relation" onclick="renameRelation()" />
					<br></br>
			<div id="renameTopics">
				#{ifnot toBeDeleted}
	
				<p>No Relations to rename !!</p>
	
				#{/ifnot} #{if toBeDeleted}
				<label for="newName" id="renamelabel">New Relation Name</label>
			 <input name="typemsg"
				id="newName" value="" type="text" />
				<br></br>
				<select name="mydropdown" id="rename">
					#{list items:toBeDeleted, as: 'task' }
					<option id="" value="${task}">${task}</option> #{/list}
				</select> #{/if}
				<br></br>
				<input type="submit" id="ren"
					value="Rename Selected Relation" onclick="renameRel()" />
	
			</div>

              </div>
		<div id="invitees" class="invitees" style="display: none">
			People to invite
			<button id="ok" onclick="javascript:hideDiv()">OK</button>
		</div>





		<input type="hidden" id="type" name="type" value=${type}> <input
			type="hidden" id="page" name="page" value=${page}> <input
			type="hidden" id="total" name="total" value=${total}> <a
			id="next" style="display: none"
			href="javascript:display(document.getElementById('page').value,document.getElementById('total').value)">
			ShownextIdeas</a>

<label id="noPosted"></label>
		<div id="posted">
			
		</div>



		<div id="drafted">
			<label>Your Drafted Ideas</label>
			<p></p>
			<label id="noDrafted"></label>
		</div>
		
		<div id="inviteHere"  style="display:none">
			Username: <input type="text" size="20" id="toBeInvited" onkeyup="getTagsghUserNM(this.value)">
			<button onclick="javascript:inviteAny()">Invite to be organizer</button>
		</div>


			<form name="input" action="#" method="get">

				<a href='#' id="restrictOrganizer"
					onclick="javascript:resOrganizers()">Restrict Organizer</a>
			</form>
			<div>
				<div id="organizers"></div>
			</div>
			<div id="label"></div>
			<input id="topicID" type="hidden" value="${topicId}">


		<input type="submit" id="createYourOwnIdea" style="display: none"
			name="createIdea" value="createYourOwnIdea"
			onclick="javascript:slidedown('newidea')" />

		<div>
			<div id="members" style="display: none" class="white_content"></div>

		</div>

		<div id="newidea" style="display: none">
			Idea_Title:<br> <input type="text"  id="createTitle" name="newIdea"
                                              />  <label id="ideatitleexp">Title Required</label><br />
                        <p></p>
			Idea_Description:<br> <textarea id="createDescr"
                                                    name="newIdea" rows = "3" cols="30 max" ></textarea><label id="ideadescrexp">Description Required</label> <br />
                        <input
				type="submit" name="post" value="post"
				onclick="javascript:createpostIdea()" />
                        <input type="submit"
				name="draft" value="draft" onclick="javascript:draftIdea()" />
                        <input
				type="submit" name="discard" value="discard"
				onclick="javascript:discard('newIdea')" />
		</div>
	

		 <div id="editDraft" style="display: none" class="white_content">

			<input type="hidden" id="ideaid" name="ideaId" />
                 Idea_Title : <input type="text"
                            id="drafttitle" name="newIdea" /><label id="drafttitleexp"></label>
                 <br>
             Idea_Description :

             <textarea
                            id="draftdescr" name="newIdea" rows = "3" cols="30 max" ></textarea><label id="draftdescrexp"></label>
                       <br>
                       <br>
                            <input type="submit" name="post"
				value="post"
				onclick="javascript:postDraftIdea(document.getElementById('ideaid').value)" />
			<input type="submit" name="draft" value="draft"
				onclick="javascript:draftDraftIdea(document.getElementById('ideaid').value)" />
			<input type="submit" name="discard" value="discard"
				onclick="discard('editDraft')" />

		</div>


	</div>

	<input type="hidden" id="duplicatesShown?" value="duplicatesNotShown" />
	<input type="hidden" id="TagTypeId" value=1 />
	<input type="hidden" id="TagType" value="ay kalam" />
	<input type="hidden" id="TagToEdit" value=1 />
	<div id="zeinTag" style="display: none" class="white_content">
		<input type="button" id="showTags" value="Show Tags"
			onclick="showTags()" /> <input type="button" id="hideOptions"
			value="Hide Options" onclick="hideOptions()" /> <input type="button"
			id="hideTags" value="Hide Tags" onclick="hideTags()" /> <input
			type="button" id="AddTag" value="Add Tag"
			onclick="addTag(document.getElementById('TagTypeId').value)" /> <input
			type="button" id="showBox" value="Create Tag" onclick="showBox()" />
		<input type="text" id="TagBox" /> <input type="button" id="Cancel"
			value="Cancel" onclick="hideBox()" /> <input type="button"
			id="ClosezeinTag" value="x" onclick="hideTagTag()"
			style="float: right" />
		<div id="Tag"></div>
		<input type="text" id="EditBox" />
		<div id="TagOptions"></div>
	</div>
	<div id="overlay"
		style="display: block; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; background-color: black; opacity: .80;">Something
		here</div>


	<div class="sidebar">
		#{if isOrganizer } 
		<P id="result_lock"> </P>
		#{if topicisLocked}
	<a id="unlock_topic" href="#" onClick="javascript:LockTopic('unlock')">unlock Topic</a> 
		
		#{/if}
				#{ifnot topicisLocked}
		
		<a  id="lock_topic" href="#" onClick="javascript:LockTopic('lock')">Lock Topic</a> 
			#{/ifnot}
		#{/if}
		<form>
			<input id="follow"   class="formbutton" type="button"
				onclick="followTopic()" value="Follow" name="FollowButton" style="background-color:green;display:none;">
			<input id="unfollow"  style="display:none"  class="formbutton" type="button"
				onclick="unfollowTopic()" value="Unfollow" name="UnfollowButton">
			<br> <br> <input id="showDuplicatedButton"
				class="formbutton" type="button" value="Duplicated Ideas"
				onclick="javascript:showDuplicated()" style="display:none;"/>
		</form>
		<br> <br>
		<div id="duplicateIdeas"></div>
	</div>

     
</body>
